package com.zimi.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zimi.model.SysOrgExtend;
import com.zimi.model.SysPost;
import com.zimi.model.SysPostSuperiors;
import com.zimi.model.SysPostSuperiorsExtend;
import com.zimi.service.SysPostService;
import com.zimi.service.SysPostSuperiorsService;
import com.zimi.util.CommonUtil;
import com.zimi.util.GsonUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 机构职务表 api
 *
 * @author lnintr
 * @since 2019-05-22
 */
@RestController
@RequestMapping("sys-post-superiors")
public class SysPostSuperiorsApi {

    @Autowired
    private SysPostSuperiorsService sysPostSuperiorsService;

    @GetMapping("getCurRowChecked")
    @ApiOperation("获取上级岗位")
    public Object getCurRowChecked(SysPostSuperiors superiors, int limit, int page) {

        Map resMap = sysPostSuperiorsService.getSupPostChecked(superiors.getOriginOrgId(), superiors.getPostId(), limit, page);


        Map map = new HashMap();

        map.put("code", 0);
        map.put("data", resMap.get("data"));
        map.put("count", resMap.get("total"));
        return map;
    }

    @PostMapping("save")
    @ApiOperation("保存上级岗位")
    public Object getPostById(SysPostSuperiors superiors) {
        Map map = new HashMap();
        sysPostSuperiorsService.save(superiors);

        map.put("code", 0);
        return map;
    }

    @PostMapping("moveUp")
    @ApiOperation("上移")
    public Object moveUP(SysPostSuperiors superiors) {
        Map map = new HashMap();
        sysPostSuperiorsService.moveUp(superiors);

        map.put("code", 0);
        return map;
    }

    @PostMapping("moveDown")
    @ApiOperation("下移")
    public Object moveDown(SysPostSuperiors superiors) {
        Map map = new HashMap();
        sysPostSuperiorsService.moveDown(superiors);

        map.put("code", 0);
        return map;
    }

    @PostMapping("getCurOrgPost")
    @ApiOperation("根据机构Id查询机构和岗位信息")
    public Object getCurOrgPost(SysOrgExtend record) {
        Map<String, Object> objectMap = new HashMap<>();

        List<SysPostSuperiors> superiorsList = new SysPostSuperiors().selectList(new LambdaQueryWrapper<SysPostSuperiors>().eq(SysPostSuperiors::getOriginOrgId, record.getOrgId()).eq(SysPostSuperiors::getPostId, record.getPostId()).eq(SysPostSuperiors::getState, 1));
        List<SysOrgExtend> list = sysPostSuperiorsService.getCurOrgPost(record);

        objectMap.put("data", list);
        objectMap.put("supData", superiorsList);
        objectMap.put("code", 0);
        return objectMap;
    }
}
